#include <stdio.h>
#include <stdlib.h>
#include "list.h"

struct list_head domain_list_head;

struct domain_node {
	struct list_head domain_list_elem;
	int domain_id;
};

main()
{
	int i;
	struct domain_node *node;
	struct list_head *iter, *iter_next;

	INIT_LIST_HEAD( &domain_list_head );

	//create a test list
	for( i=0; i<10; i++ ){
		node = malloc( sizeof(struct domain_node) );
		if ( node == NULL ){
			printf( "malloc failed!\n" );
			return -1;
		}
		INIT_LIST_HEAD( &node->domain_list_elem );
		node->domain_id = i;
		list_add_tail( &node->domain_list_elem, &domain_list_head );
	}
	printf( "list created.\n" );

	//browse the list
	list_for_each( iter, &domain_list_head )
	{
		node = list_entry( iter, struct domain_node, domain_list_elem );
		printf( "node's domain_id is:%d.\n", node->domain_id);
	}
	printf( "list browsed.\n" );

	//free the list
	list_for_each_safe( iter, iter_next, &domain_list_head )
	{
		node = list_entry( iter, struct domain_node, domain_list_elem );
		list_del( iter );
		free( node );
	}
	
	printf( "list freed\n" );

	if ( !list_empty(&domain_list_head) )
		printf( "The list is NOT empty yet!\n" );
	else
		printf( "The list is now empty.\n" );

}

